home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 April / Software of the Month Club 1996 April.iso / pc / os2 / psutils / src / showchar < prev   
Text File  |  1996-02-21  |  3KB  |  123 lines

  1. #!/bin/sh
  2. # showchar: show character with information
  3. #
  4. # Copyright (C) Angus J. C. Duggan 1991-1995
  5. # See file LICENSE for details.
  6. #
  7. # usage:
  8. #       showchar Font-Name Char-Name | lpr -Pprinter
  9.  
  10. if [ $# != 2 ]; then
  11.         echo "Usage: `basename $0` Font-Name Char-Name" >&2
  12.         exit 1
  13. fi
  14.  
  15. cat <<EOF
  16. %!
  17. % Get character metrics and bounding box for $1
  18. /ns 30 string def
  19. /fname /$1 def
  20. /cname /$2 def
  21. /fn fname findfont 1000 scalefont def
  22. /thin 0.7 def
  23. /reduction 2.0 def
  24.  
  25. /sn { ns cvs show } def
  26. /sc { (\()show exch sn (,)show sn (\))show } def
  27.  
  28. /Times-Roman findfont 10 scalefont setfont
  29.  
  30. 72 242 translate % one inch in, 3 1/2 inch up
  31. newpath 0 0 moveto
  32. gsave   % print character name
  33.    0 468 rmoveto
  34.    ($2 from font $1 displayed on `date` by `basename $0` 1.00 (C) AJCD 1991)
  35.    show 
  36. grestore
  37.  
  38. gsave
  39.    thin setlinewidth  % cross hairs
  40.    -9 0 rmoveto 18 0 rlineto
  41.    -9 -9 rmoveto 0 18 rlineto
  42.    stroke  % position info
  43.    -9 -9 moveto ((0,0)) stringwidth pop neg 0 rmoveto
  44.    ((0,0)) show
  45. grestore
  46.  
  47. % create encoding with a single character at all positions
  48. /MyEncoding 256 array def
  49.  
  50. 0 1 255 { % fill out with notdefs
  51.    MyEncoding exch cname put
  52. } for
  53.  
  54. fn dup length dict begin
  55.   {1 index /FID ne {def} {pop pop} ifelse} forall
  56.   /Encoding MyEncoding def
  57.   currentdict
  58. end /newfont exch definefont
  59. /fn exch def
  60. /en MyEncoding def
  61.  
  62. gsave  % draw character (enlarged)
  63.   .75 setgray
  64.   fn 1 reduction div scalefont setfont
  65.   (\000) show
  66. grestore
  67.  
  68. % show character info
  69. fn /Metrics known {
  70.    dup fn /Metrics get exch get 
  71.    dup type /arraytype eq {
  72.       dup length 2 eq
  73.       {1 get 0} {dup 2 get exch 3 get} ifelse
  74.    } {
  75.       round 0
  76.    } ifelse
  77. } {
  78.    gsave
  79.       fn setfont (\000) stringwidth round exch round exch
  80.    grestore
  81. } ifelse
  82. gsave   % show width
  83.    thin setlinewidth
  84.    2 copy
  85.    reduction div exch reduction div exch rlineto
  86.    gsave
  87.       1 1 rmoveto sc
  88.    grestore
  89.    -4 -3 rlineto 0 6 rmoveto 4 -3 rlineto
  90.    stroke
  91. grestore
  92.  
  93. gsave
  94.    gsave  % get bounding box
  95.       fn setfont
  96.       (\000) true charpath flattenpath pathbbox
  97.    grestore
  98.    thin setlinewidth
  99.    3 index reduction div  % put coords on top of stack
  100.    3 index reduction div
  101.    3 index reduction div
  102.    3 index reduction div
  103.    3 index 3 index moveto
  104.    gsave  % llx lly
  105.       0 -9 rmoveto 7 index 7 index sc
  106.    grestore
  107.    1 index 3 index lineto
  108.    gsave  % urx lly
  109.       0 -9 rmoveto 5 index 7 index sc
  110.    grestore
  111.    1 index 1 index lineto
  112.    gsave  % urx ury
  113.       0 9 rmoveto 5 index 5 index sc
  114.    grestore
  115.    3 index 1 index lineto
  116.    gsave  % llx ury
  117.       0 9 rmoveto 7 index 5 index sc
  118.    grestore
  119.    closepath stroke
  120. grestore
  121. showpage
  122. EOF
  123.